package com.example.controller.adm;

import com.example.context.PageResult;
import com.example.entity.ProductCateDO;
import com.example.service.adm.AdmProductCateService;
import com.example.vo.cate.AdmProdCatePageReq;
import com.example.vo.cate.ProdCateReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品类别管理")
@RestController
@RequestMapping("/api/admin/product/cate")
public class AdmProductCateController {

    @Resource
    private AdmProductCateService productCateService;

    @GetMapping
    @Operation(summary = "获取商品类别列表")
    public PageResult<ProductCateDO> list(@Valid AdmProdCatePageReq req) {
        return productCateService.pageQuery(req);
    }

    @PostMapping
    @Operation(summary = "新增商品类别")
    public void add(@Valid @RequestBody ProdCateReq req) {
        productCateService.add(req);
    }

    @PutMapping
    @Operation(summary = "修改商品类别")
    public void update(@Valid @RequestBody ProdCateReq req) {
        productCateService.modify(req);
    }

    @DeleteMapping
    @Operation(summary = "删除商品类别", description = "删除商品类别，根据商品id数组",
            parameters = {
                    @Parameter(name = "ids", description = "商品类别id数组", required = true)
            })
    public void delete(@RequestParam("ids") Long[] ids) {
        productCateService.delete(ids);
    }

}
